package Classes.Managers// ActionScript file
{
	import Classes.GameUtils.GU_DataTransform;
	import Classes.Interfaces.I_NeedSWFSource;
	
	import MV_BMP.MovieClip_BMP;
	
	import flash.display.MovieClip;
	import flash.system.ApplicationDomain;

	/**
	 *裸模管理器 
	 * @author 葛增文
	 * 
	 */	
	public class M_BaseCartoons extends Manager implements I_NeedSWFSource
	{
		private var _baseCartoonsFolderPath:String;
		private static var _instance:M_BaseCartoons;/*静态引用*/
		private var _baseCartoonsObj:Object;/*裸模数据存储器*/
		private var _loadingObj:Object;/*正在载入裸模的对象*/
		
		public function M_BaseCartoons():void
		{
			_instance=this;
			this.init();
		}
		
		private function init():void
		{
			this._baseCartoonsObj=new Object;
		}
		
		override public function importData():void
		{
			this._baseCartoonsFolderPath=M_ConfigData.instance.baseCartoonsUrl;
			var baseCartoonsCSV:String=M_ConfigData.instance.getCSVByName("裸模动画配置表");
			var baseCartoonsAry:Array=GU_DataTransform.csvTransformObjsAry(baseCartoonsCSV,6);
			for(var i:int=0;i<baseCartoonsAry.length;i++)
			{
				var baseCartoonDataObj:Object=baseCartoonsAry[i];
				if(!this.baseCartoonsObj.hasOwnProperty(baseCartoonDataObj.baseCartoonType))
				{
					this.baseCartoonsObj[baseCartoonDataObj.baseCartoonType]={cartoonsSource:baseCartoonDataObj.cartoonsSource,hasCartoon:false,actions:new Object}
				}
				this.baseCartoonsObj[baseCartoonDataObj.baseCartoonType].actions[baseCartoonDataObj.actionName]={className:baseCartoonDataObj.className,setX:baseCartoonDataObj.setX,setY:baseCartoonDataObj.setY};
			}
			this.importOver(1);
		}
		
		/**
		 *根据裸模类型获得裸模动画配置对象 
		 * @param type
		 * @return 
		 * 
		 */		
		public function getBaseCartoonObjByType(type:String):Object
		{
			if(!this.baseCartoonsObj.hasOwnProperty(type))throw new Error("该模型不存在");
			return this.baseCartoonsObj[type];
		}
		
		/**
		 *载入裸模动画需求 
		 * @param baseCartoonType
		 * @param callback
		 * 
		 */		
		public function needLoadBaseCartoon(baseCartoonType:String,callback:Function):void
		{
			var baseCartoonObj:Object=this.getBaseCartoonObjByType(baseCartoonType);
			if(!baseCartoonObj.hasCartoon)
			{
				if(M_LoadSWFSource.instance.checkSource(baseCartoonObj.cartoonsSource))
				{
					baseCartoonObj.hasCartoon=true;
				}
				else if(!this.loadingObj)
				{
					this.loadingObj={callback:callback,baseCartoonType:baseCartoonType};
					var sourceName:String=baseCartoonObj.cartoonsSource;
					var sourcePath:String=this.baseCartoonsFolderPath+sourceName;
					M_LoadSWFSource.instance.needLoad(this,sourcePath,sourceName);
					return;
				}
				else
				{
					throw new Error("正在载入其他资源")
				}
			}
			callback(baseCartoonType);
		}
		
		public function sourceLoadOver(sourceName:String):void
		{
			var nowCallback:Function=this.loadingObj.callback;
			var nowBaseCartoonType:String=this.loadingObj.baseCartoonType;
			this.loadingObj=null;
			this.needLoadBaseCartoon(nowBaseCartoonType,nowCallback);
		}

		/*getter & setter*/
		public static function get instance():M_BaseCartoons
		{
			return _instance;
		}

		public function get baseCartoonsObj():Object
		{
			return _baseCartoonsObj;
		}

		public function get loadingObj():Object
		{
			return _loadingObj;
		}

		public function set loadingObj(value:Object):void
		{
			_loadingObj = value;
		}

		public function get baseCartoonsFolderPath():String
		{
			return _baseCartoonsFolderPath;
		}


	}
}